# 在一个终端中 ：dask scheduler 另一个终端：dask worker tcp://localhost:8786
import time
import random

def inc(x):
    time.sleep(random.random())
    return x + 1

def double(x):
    time.sleep(random.random())
    return 2 * x

def add(x, y):
    time.sleep(random.random())
    return x + y


from dask.distributed import Client, LocalCluster
client = Client('localhost:8786')
future = client.submit(inc, 1)  # returns immediately with pending future

print(future.result())
x = client.submit(inc, 1)
y = client.submit(double, 2)
z = client.submit(add, x, y)
print(z.result())